package acs.offer.util;

import acs.offer.collection.Params;
import acs.offer.constant.Constant;

import java.util.HashMap;
import java.util.Map;

public class ServerCache {
	public static final String OFFER_CACHE_KEY="OFFER_CACHE_KEY";
	
	private Map<String, Object> map = new HashMap<>();
	private ServerCache() {};
	
	private static ServerCache instance=new ServerCache();
	public static ServerCache getInstance() {
		return instance;
	}

	public String getCacheKey(Params params){
		String requestType = params.get(Constant.REQUEST_TYPE);
		Map<String,String>  map=params.get(Constant.REQUEST_PARAMS);
		return requestType + ":" + map.toString();
	}

	public <T> T remove(String key) {
		return (T) map.remove(key);
	}
	
	public <T> T get(String key) {
		return (T) map.get(key);
	}

	public <T> T getOrDefault(String key,T t) {
		return (T) map.getOrDefault(key, t);
	}

	public ServerCache put(String key, Object value) {
		map.put(key, value);
		return this;
	}

	public static ServerCache build() {
		return new ServerCache();
	}
	
	
    
}
